/**
 * 公告详情
 */
angular.module('inspinia').controller("noticeDetailCtrl",function($scope, $http, $state, $stateParams) {
	//数据源
	$scope.sysType=[{text:"商户",value:'1'},{text:"代理商",value:'2'}];
	$scope.agentBusiness = [{text:"全部",value:'0'},{text:"指定一级代理商下（包括下级发展）的商户",value:'1'}];
	$scope.baseInfo = {agentBusiness:'0'};
	$scope.team = [{text:'全部',value:'0'},{text:'直营',value:'1'},{text:'非直营',value:'2'}];
	$scope.isAll = [{text:'所有代理商',value:'1'},{text:'所有一级代理商',value:'2'}];
    $scope.showStatuses=[{text:"非弹窗提示",value:'0'},{text:"弹窗提示",value:'1'}];
	$scope.$state = $state;
    $scope.oemTypes=[];//缓存所有指定组织
    $scope.oemListResult=false;
    $scope.oemListes=[];
	var id = $stateParams.id;

	$scope.noticeTypes=[{text:"图片类",value:'1'},{text:"图文类",value:'0'}];
	//是否带参数
	$scope.isWithParamList=[{text:"是",value:'1'},{text:"否",value:'0'}];
	
	$http.get('notice/selectById/'+$stateParams.id).success(function(msg){
		$scope.noticeInfo = msg.notice;
		$scope.customerData = msg.products;
        $scope.oemTypes=msg.oemTypes;
        $scope.oemListes=msg.oemListes;

		$scope.selectAgentsGrid.data = msg.selectAgents;
		$scope.teamProducts = msg.products;

		if(msg.notice.agentNo == '0'){
			$scope.baseInfo.agentBusiness = '0';
		} else if(msg.notice.agentNo != '0'){
			$scope.baseInfo.agentBusiness = '1';
		}
		if(msg.notice.receiveType == '1'){
			$scope.baseInfo.isAll = '1';
		}
		else if(msg.notice.receiveType == '2'){
			$scope.baseInfo.isAll = '2';
		}
        if(msg.notice.oemType.indexOf("11")!=-1){
            $scope.oemListResult=true;
        }
	}).error(function(){
	})
	
	//业务产品表格
	$scope.productsGrid = { // 配置表格
		data : 'customerData',
		enableHorizontalScrollbar : 0, // 去掉滚动条
		enableVerticalScrollbar : 1, // 去掉滚动条
		columnDefs : [ // 表格数据
		               {field : 'teamName',displayName : '所属组织'},
		               {field : 'bpName',displayName : '业务产品名称'},
		               {field : 'remark',displayName : '业务产品说明'}],
		onRegisterApi : function(gridApi) {
			$scope.gridApiProduct = gridApi;
		}
	};

	$scope.selectAgentsGrid = { // 配置表格
		data: null,
		enableHorizontalScrollbar: 0, // 去掉滚动条
		enableVerticalScrollbar: 1, // 去掉滚动条
		columnDefs: [
			{ field: 'agentName', displayName: '代理商名称' }
			, { field: 'agentNo', displayName: '代理商编号' }
		],
		onRegisterApi: function (gridApi) {
			$scope.selectAgentsGridApi = gridApi;
		},
		isRowSelectable: function(row){ // 选中行
			//console.log("所属组织表格，选中了组织ID:" + row.entity.teamId)
		}
	};

	$scope.teamProducts = [];
	$scope.teamProductsGrid = { // 配置表格
		data: 'teamProducts',
		enableHorizontalScrollbar: 0, // 去掉滚动条
		enableVerticalScrollbar: 1, // 去掉滚动条
		enableSelectAll: true,
		checkedState: true,
		columnDefs: [
			{ field: 'bpName', displayName: '业务产品' }
		],
		onRegisterApi: function (gridApi) {
			$scope.teamProductsApi = gridApi;
			for (const uploaderTitleImgFlagKey in uploaderTitleImgFlag) {

			}
			$scope.teamProductsApi.selection.on.rowSelectionChanged($scope,function(row,event){
				//$scope.listProductByTeams();
			});
			$scope.teamProductsApi.selection.on.rowSelectionChangedBatch($scope,function(row,event){
				//$scope.listProductByTeams();
			});
		},
		isRowSelectable: function(row){ // 选中行
		}
	};

}).filter('trustHtml', function ($sce) {
    return function (input) {
        return $sce.trustAsHtml(input);
    }
});;
